<?php

/**
 * This is the model class for table "options".
 *
 * The followings are the available columns in table 'options':
 * @property integer $id
 * @property integer $question_id
 * @property string $name
 * @property string $correct_option
 * @property string $status
 * @property string $created
 * @property string $modified
 */
class Options extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Options the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'options';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('question_id, name, correct_option', 'required'),
			array('question_id', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>200),
			array('correct_option', 'length', 'max'=>3),
			
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, question_id, name, correct_option,created, modified', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'question_id' => 'Question',
			'name' => 'Name',
			'correct_option' => 'Correct Option',
		
			'created' => 'Created',
			'modified' => 'Modified',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('question_id',$this->question_id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('correct_option',$this->correct_option,true);

		$criteria->compare('created',$this->created,true);
		$criteria->compare('modified',$this->modified,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
public static function getList($type, $arrParams=array())
	{
		switch ($type)
		{
			case "QUESTION-ID":
				$options = Options::model()->findAll(
					'question_id=?',array($arrParams['questionid'])
					);
				return $options;
				break;
		} 
	}
		//get  model object of specific type
	public function getModel($type, $arrParams) 
	{
		switch($type)
		{		
			case "CHAPTER-ID":
				$chapter=Chapter::model()->findByPk((int)$arrParams['chapterid']);
				return $chapter;
			break;
			case "OPTION-ID":
				$option=Options::model()->findByPk((int)$arrParams['optionid']);
				return $option;
			break;
			case "CORRECT-OPTION":
				$options = Options::model()->find(
					'question_id=? and correct_option="yes"',array($arrParams['questionid'])
					);
				return $options;
				break;
			case "QUESTION-ID":
				$options = Options::model()->findAll(
					'question_id=?',array($arrParams['questionid'])
					);
				return $options;
				break;
		}
	}
}